package com.digitalchina.lxnsy.activity.old;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Button;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessAccount;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.widget.EditTextWithClear;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.digitalchina.lxnsy.constant.MSG.MSG_SET_NEW_PWD_FIELD;
import static com.digitalchina.lxnsy.constant.MSG.MSG_SET_NEW_PWD_SUCCESS;

/**
 * ================================================
 * 项目名称：bigdata
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2016/12/6 14:57
 * 修改备注：
 * ================================================
 */
public class ForgetPasswordStepTwoActivity extends BaseActivity {


    @Bind(R.id.forget_pd_et_password)
    EditTextWithClear forgetPdEtPassword;
    @Bind(R.id.forget_pd_et_confirm_password)
    EditTextWithClear forgetPdEtConfirmPassword;
    @Bind(R.id.forget_pd_bt_confirm_modification)
    Button forgetPdBtConfirmModification;

    private String mobilePhone;
    private String strPassword;
    private String strConfirmPassword;

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_forget_password_step_two);
        setTitle("重置密码");
    }

    @Override
    public void initMember() {
        mobilePhone = (String) getIntent().getSerializableExtra("mobilePhone");
    }

    @Override
    public void addListener() {

    }

    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case MSG_SET_NEW_PWD_SUCCESS:
                        callBack(msg.obj);
                        break;
                    case MSG_SET_NEW_PWD_FIELD:
                        showToast(msg.obj.toString());
                        break;
                }
            }
        };
    }

    @Override
    public void callBack(Object object) {
        showToast("密码重置成功!");
        finish();
    }

    @Override
    public void rightOnClick() {

    }


    @OnClick(R.id.forget_pd_bt_confirm_modification)
    public void onClick() {
        confirmModification();
    }

    /**
     * 确认重置密码
     */
    private void confirmModification() {

        strPassword = StringUtil.getEditText(forgetPdEtPassword);
        strConfirmPassword = StringUtil.getEditText(forgetPdEtConfirmPassword);

        if (StringUtil.isStrEmpty(strPassword)) {
            showToast("新密码不能为空");
            return;
        }

        if (StringUtil.isStrEmpty(strConfirmPassword)) {
            showToast("确认新密码不能为空");
            return;
        }

        if (!StringUtil.isStrEqual(strPassword, strConfirmPassword)) {
            showToast("两次输入的密码不一致");
            return;
        }

//        if (strConfirmPassword.length() < 6 ||
//                !RegexpUtil.isRegexpValidate(strConfirmPassword, RegexpUtil.LETTER_AND_NUMBER_REGEXP)) {
//            showToast("密码为6-20个字符、字母和数字组合");
//            return;
//        }

        BusinessAccount.setNewPwd(this, mobilePhone, strPassword, strConfirmPassword, mHandler);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
